package com.lxyk.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//注册拦截器
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自己的拦截器 并设置拦截请求
        //addPathPatterns() :拦截此路径的请求
        //excludePathPatterns():不拦截此路径的请求
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**")//拦截所有
        .excludePathPatterns("/","/login","/index.html","/css/**","/fonts/**","/images/**","/js/**","favicon.ico");//favicon.ico是图标
         /*这些路径前必须有一个斜杠 图标除外*/
    }
    //在配置类添加视图映射

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //当你访问index.html时 直接跳转到index登录界面
        registry.addViewController("index.html").setViewName("index");
    }
}
